/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Consultorio.java
 *
 * Created on 21/09/2011, 09:18:53
 */
package view;

import control.ConsultaControler;
import control.Controler;
import javax.swing.JOptionPane;
import model.Usuario;
import util.Constantes;

/**
 *
 * @author Fabricio
 */
public class Consultorio extends javax.swing.JFrame {

    private Usuario user;
    private Controler controler;

    /** Creates new form Consultorio */
    public Consultorio(Usuario u, Controler c) {
        user = u;
        controler = c;
        initComponents();
    }

    public Controler getControler() {
        return controler;
    }

    public void setControler(Controler controler) {
        this.controler = controler;
    }

    public Usuario getUser() {
        return user;
    }

    public void setUser(Usuario user) {
        this.user = user;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mbPrincipal = new javax.swing.JMenuBar();
        mCadastrar = new javax.swing.JMenu();
        miCadastroMedico = new javax.swing.JMenuItem();
        miCadastroCliente = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        miCadastroFuncao = new javax.swing.JMenuItem();
        miCadastroFuncionario = new javax.swing.JMenuItem();
        miCadConvenio = new javax.swing.JMenuItem();
        mAtualizar = new javax.swing.JMenu();
        miAtualizarUsuario = new javax.swing.JMenuItem();
        miAtualizarPaciente = new javax.swing.JMenuItem();
        miDespesa = new javax.swing.JMenuItem();
        mExcluir = new javax.swing.JMenu();
        miExcluirUsuario = new javax.swing.JMenuItem();
        miExcluirPaciente = new javax.swing.JMenuItem();
        Remarcar = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        menuItemRemarcar = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        exibirAlterarDados = new javax.swing.JMenuItem();
        jMenuRelatorios = new javax.swing.JMenu();
        jMenuRecebimentos = new javax.swing.JMenuItem();
        jMenuDespesas = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Consultorio");
        setName("consultorio"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        mCadastrar.setText("Cadastrar");

        miCadastroMedico.setText("Médico");
        miCadastroMedico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadastroMedicoActionPerformed(evt);
            }
        });
        mCadastrar.add(miCadastroMedico);

        miCadastroCliente.setText("Paciente");
        miCadastroCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadastroClienteActionPerformed(evt);
            }
        });
        mCadastrar.add(miCadastroCliente);

        jMenuItem8.setText("Despesa");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        mCadastrar.add(jMenuItem8);

        miCadastroFuncao.setText("Função");
        miCadastroFuncao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadastroFuncaoActionPerformed(evt);
            }
        });
        mCadastrar.add(miCadastroFuncao);

        miCadastroFuncionario.setText("Funcionário");
        miCadastroFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadastroFuncionarioActionPerformed(evt);
            }
        });
        mCadastrar.add(miCadastroFuncionario);

        miCadConvenio.setText("Convênio");
        miCadConvenio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miCadConvenioActionPerformed(evt);
            }
        });
        mCadastrar.add(miCadConvenio);

        mbPrincipal.add(mCadastrar);

        mAtualizar.setText("Atualizar");

        miAtualizarUsuario.setText("Usuário");
        miAtualizarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAtualizarUsuarioActionPerformed(evt);
            }
        });
        mAtualizar.add(miAtualizarUsuario);

        miAtualizarPaciente.setText("Paciente");
        miAtualizarPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAtualizarPacienteActionPerformed(evt);
            }
        });
        mAtualizar.add(miAtualizarPaciente);

        miDespesa.setText("Despesa");
        mAtualizar.add(miDespesa);

        mbPrincipal.add(mAtualizar);

        mExcluir.setText("Excluir");

        miExcluirUsuario.setText("Usuário");
        miExcluirUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExcluirUsuarioActionPerformed(evt);
            }
        });
        mExcluir.add(miExcluirUsuario);

        miExcluirPaciente.setText("Paciente");
        miExcluirPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExcluirPacienteActionPerformed(evt);
            }
        });
        mExcluir.add(miExcluirPaciente);

        mbPrincipal.add(mExcluir);

        Remarcar.setText("Consulta");

        jMenuItem3.setText("Marcar");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        Remarcar.add(jMenuItem3);

        menuItemRemarcar.setText("Remarcar");
        menuItemRemarcar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemRemarcarActionPerformed(evt);
            }
        });
        Remarcar.add(menuItemRemarcar);

        jMenuItem5.setText("Desmarcar");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        Remarcar.add(jMenuItem5);

        exibirAlterarDados.setText("Prontuario");
        exibirAlterarDados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exibirAlterarDadosActionPerformed(evt);
            }
        });
        Remarcar.add(exibirAlterarDados);

        mbPrincipal.add(Remarcar);

        jMenuRelatorios.setText("Relatórios");
        jMenuRelatorios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuRelatoriosActionPerformed(evt);
            }
        });

        jMenuRecebimentos.setText("Recebimentos");
        jMenuRecebimentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuRecebimentosActionPerformed(evt);
            }
        });
        jMenuRelatorios.add(jMenuRecebimentos);

        jMenuDespesas.setText("Despesas");
        jMenuDespesas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuDespesasActionPerformed(evt);
            }
        });
        jMenuRelatorios.add(jMenuDespesas);

        mbPrincipal.add(jMenuRelatorios);

        setJMenuBar(mbPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void miCadastroMedicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadastroMedicoActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new CadastroMedico(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miCadastroMedicoActionPerformed

private void miCadastroFuncaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadastroFuncaoActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new CadastrarFuncao(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miCadastroFuncaoActionPerformed

private void miCadastroFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadastroFuncionarioActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new CadastroFuncionario(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miCadastroFuncionarioActionPerformed

private void miCadastroClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadastroClienteActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new CadastrarPaciente(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miCadastroClienteActionPerformed

private void miCadConvenioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miCadConvenioActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new CadastrarConvenio(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miCadConvenioActionPerformed

private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            CadastrarDespesa fcad = new CadastrarDespesa(controler);
            fcad.getJfCpf().setText(user.getUserCpf());
            fcad.setVisible(true);
        }
    });
}//GEN-LAST:event_jMenuItem8ActionPerformed

private void miExcluirUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExcluirUsuarioActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new ExcluirUsuario(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miExcluirUsuarioActionPerformed

private void miExcluirPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExcluirPacienteActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new ExcluirPaciente(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miExcluirPacienteActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    ConsultaControler.marcar_consulta();
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
    ConsultaControler.desmarcar_consulta();
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void menuItemRemarcarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemRemarcarActionPerformed
    ConsultaControler.buscar_para_alterar(0);
}//GEN-LAST:event_menuItemRemarcarActionPerformed

private void miAtualizarPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAtualizarPacienteActionPerformed
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new AtualizarPaciente(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miAtualizarPacienteActionPerformed

private void miAtualizarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAtualizarUsuarioActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new AtualizarUsuario(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_miAtualizarUsuarioActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
}//GEN-LAST:event_formWindowClosing

private void exibirAlterarDadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exibirAlterarDadosActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    ConsultaControler.buscar_para_alterar(1);
}//GEN-LAST:event_exibirAlterarDadosActionPerformed

private void jMenuRecebimentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuRecebimentosActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new RelatorioRecebimentos(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_jMenuRecebimentosActionPerformed

private void jMenuDespesasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuDespesasActionPerformed
    if(!user.getUserType().toString().equals(Constantes.ADMINISTRADOR)){
        JOptionPane.showMessageDialog(null, Constantes.NOT_AUTHORIZED);
        return;
    }
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            new RelatorioDespesas(controler).setVisible(true);
        }
    });
}//GEN-LAST:event_jMenuDespesasActionPerformed

private void jMenuRelatoriosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuRelatoriosActionPerformed
}//GEN-LAST:event_jMenuRelatoriosActionPerformed

    private void mCadastrarActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu Remarcar;
    private javax.swing.JMenuItem exibirAlterarDados;
    private javax.swing.JMenuItem jMenuDespesas;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuRecebimentos;
    private javax.swing.JMenu jMenuRelatorios;
    private javax.swing.JMenu mAtualizar;
    private javax.swing.JMenu mCadastrar;
    private javax.swing.JMenu mExcluir;
    private javax.swing.JMenuBar mbPrincipal;
    private javax.swing.JMenuItem menuItemRemarcar;
    private javax.swing.JMenuItem miAtualizarPaciente;
    private javax.swing.JMenuItem miAtualizarUsuario;
    private javax.swing.JMenuItem miCadConvenio;
    private javax.swing.JMenuItem miCadastroCliente;
    private javax.swing.JMenuItem miCadastroFuncao;
    private javax.swing.JMenuItem miCadastroFuncionario;
    private javax.swing.JMenuItem miCadastroMedico;
    private javax.swing.JMenuItem miDespesa;
    private javax.swing.JMenuItem miExcluirPaciente;
    private javax.swing.JMenuItem miExcluirUsuario;
    // End of variables declaration//GEN-END:variables
}
